<template>
  <!-- 其他费用-->
  <view class="normal-login-container">

    <view class="item-wrap" style="margin-bottom: 0">
      <view class="lineBottom10">
        <uni-section title="出险相关信息" type="line"/>
      </view>

      <view style="margin: 8rpx 20rpx 8rpx 20rpx">
        <uni-forms ref="ruleForm" :rules="rules" :label-position="boole ? 'top' : 'left'" :model="ruleForm"
                   labelWidth="auto">

          <uni-forms-item label="是否个人垫付:" name="advancePayment" :required="boole">
            <text class="advancePayment"/>
            <uni-data-select v-if="boole" v-model="ruleForm.advancePayment" :localdata="range"
                             placeholder="请选择是否个人垫付"
                             :clear="true" filterable/>
            <text v-else> {{
                ruleForm.advancePayment == '1' ? '是' : ruleForm.advancePayment == '2' ? '否' : ''
              }}
            </text>
          </uni-forms-item>


          <uni-forms-item label="个人垫付费用:" name="advancePaymentCost" :required="boole"
                          v-if="ruleForm.advancePayment == '1'">
            <text class="advancePaymentCost"/>
            <uni-easyinput v-if="boole" v-model="ruleForm.advancePaymentCost"
                           @blur="blurAmount('advancePaymentCost')"
                           placeholder="请输入个人垫付费用"/>
            <text v-else> {{ ruleForm.advancePaymentCost || '-' }}</text>
          </uni-forms-item>

          <uni-forms-item label="备注:">
            <uni-easyinput type="textarea" v-if="boole" :maxlength="500"
                           v-model="ruleForm.outDangerRemark" placeholder="请输入备注"/>
            <text v-else>{{ ruleForm.outDangerRemark || '-' }}</text>
          </uni-forms-item>

        </uni-forms>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'relatedInfo',//出险相关信息
  components: {},
  props: {
    value: {
      type: Object,
      default: {},
    },
    boole: {
      type: Boolean,
      default: true,
    },
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    handleLabel() {
      return function (arr, type) {
        let name = "";
        arr.map((v) => {
          if (type == v.value) {
            name = v.label;
          }
        });
        return name;
      };
    },
  },
  data() {
    return {
      range: [
        {value: "1", text: "是"},
        {value: "2", text: "否"},
      ],
      rules:{
        advancePayment: {
          rules: [
            {
              required: true,
              errorMessage: "请选择是否个人垫付",
              validateTrigger: "bind",
            },
          ],
        },
        advancePaymentCost: {
          rules: [
            {
              required: true,
              errorMessage: "请输入个人垫付费用",
              validateTrigger: "blur",
            },
          ],
        },
      }
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    blurAmount(str) {
      if (this.ruleForm[str]) {
        let msg = /^(?:[1-9]\d*|0)(?:\.\d+)?$/;
        if (!msg.test(this.ruleForm[str])) {
          this.ruleForm[str] = "";
        } else {
          this.ruleForm[str] = this.ruleForm[str]
              .toString()
              .match(/^\d+(?:\.\d{0,2})?/)[0];
        }
      }
    },


    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm
            .validate()
            .then((res) => {
              resolve();
            })
            .catch((err) => {
              let key = ".flex-col" + ">>>" + "." + err[0].key;
              reject(key);
            });
      });
    },
  },
};
</script>

<style scoped lang=""></style>


